home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / t3_1 / sources.lha / sources / comp / primops / m68arith.t < prev    next >
Encoding:
Text File  |  1988-02-05  |  11.2 KB  |  316 lines

  1. (herald m68arith
  2.   (env (make-empty-early-binding-locale 'nil) primops))
  3.  
  4. ;;; Copyright (c) 1985 Yale University
  5. ;;;     Authors: N Adams, R Kelsey, D Kranz, J Philbin, J Rees.
  6. ;;; This material was developed by the T Project at the Yale University Computer 
  7. ;;; Science Department.  Permission to copy this software, to redistribute it, 
  8. ;;; and to use it for any purpose is granted, subject to the following restric-
  9. ;;; tions and understandings.
  10. ;;; 1. Any copy made of this software must include this copyright notice in full.
  11. ;;; 2. Users of this software agree to make their best efforts (a) to return
  12. ;;;    to the T Project at Yale any improvements or extensions that they make,
  13. ;;;    so that these may be included in future releases; and (b) to inform
  14. ;;;    the T Project of noteworthy uses of this software.
  15. ;;; 3. All materials developed as a consequence of the use of this software
  16. ;;;    shall duly acknowledge such use, in accordance with the usual standards
  17. ;;;    of acknowledging credit in academic research.
  18. ;;; 4. Yale has made no warrantee or representation that the operation of
  19. ;;;    this software will be error-free, and Yale is under no obligation to
  20. ;;;    provide any services, by way of maintenance, update, or otherwise.
  21. ;;; 5. In conjunction with products arising from the use of this material,
  22. ;;;    there shall be no use of the name of the Yale University nor of any
  23. ;;;    adaptation thereof in any advertising, promotional, or sales literature
  24. ;;;    without prior written consent from Yale in each case.
  25. ;;;
  26.  
  27. ;;; Copyright (c) 1985 David Kranz
  28.  
  29. (define-constant fixnum-equal?
  30.   (primop fixnum-equal? ()
  31.     ((primop.generate self node)
  32.      (fixnum-comparator node 'jneq))
  33.     ((primop.presimplify self node)
  34.      (presimplify-to-conditional node))
  35.     ((primop.make-closed self)
  36.      (make-closed-conditional self))
  37.     ((primop.conditional? self) t)
  38.     ((primop.conditional-type self node)
  39.      '#[type (proc #f (proc #f) (proc #f) top fixnum fixnum)])
  40.     ((primop.type self node)
  41.      '#[type (proc #f (proc #f boolean) fixnum fixnum)])))
  42.  
  43. (define-constant fixnum-less?
  44.   (primop fixnum-less? ()
  45.     ((primop.generate self node)
  46.      (fixnum-comparator node 'jgeq))
  47.     ((primop.presimplify self node)
  48.      (presimplify-to-conditional node))
  49.     ((primop.make-closed self)
  50.      (make-closed-conditional self))
  51.     ((primop.conditional? self) t)
  52.     ((primop.conditional-type self node)
  53.      '#[type (proc #f (proc #f) (proc #f) top fixnum fixnum)])
  54.     ((primop.type self node)
  55.      '#[type (proc #f (proc #f boolean) fixnum fixnum)])))
  56.  
  57. (define-constant char=
  58.   (primop char= ()
  59.     ((primop.generate self node)
  60.      (character-comparator node 'jneq))
  61.     ((primop.presimplify self node)
  62.      (presimplify-to-conditional node))
  63.     ((primop.conditional? self) t)
  64.     ((primop.make-closed self)
  65.      (make-closed-conditional self))
  66.     ((primop.conditional-type self node)
  67.      '#[type (proc #f (proc #f) (proc #f) top char char)])
  68.     ((primop.type self node)
  69.      '#[type (proc #f (proc #f boolean) char char)])))
  70.  
  71. (define-constant char<
  72.   (primop char< ()
  73.     ((primop.generate self node)
  74.      (character-comparator node 'jgeq))
  75.     ((primop.presimplify self node)
  76.      (presimplify-to-conditional node))
  77.     ((primop.make-closed self)
  78.      (make-closed-conditional self))
  79.     ((primop.conditional? self) t)
  80.     ((primop.conditional-type self node)
  81.      '#[type (proc #f (proc #f) (proc #f) top char char)])
  82.     ((primop.type self node)
  83.      '#[type (proc #f (proc #f boolean) char char)])))
  84.  
  85. (define-constant char->ascii
  86.   (primop char->ascii ()
  87.     ((primop.generate self node)
  88.      (generate-char->ascii node))
  89.     ((primop.rep-wants self)
  90.      '(rep/char))
  91.     ((primop.arg-specs self)
  92.      '(scratch))
  93.     ((primop.type self node)
  94.      '#[type (proc #f (proc #f fixnum) char)])))
  95.  
  96. (define-constant ascii->char
  97.   (primop ascii->char ()
  98.     ((primop.generate self node)
  99.      (generate-ascii->char node))
  100.     ((primop.rep-wants self)
  101.      '(rep/integer))
  102.     ((primop.arg-specs self)
  103.      '(scratch))
  104.     ((primop.type self node)
  105.      '#[type (proc #f (proc #f char) fixnum)])))
  106.  
  107. ;;; ARITHMETIC
  108. ;;;===========================================================================
  109.  
  110. (define-constant fixnum-add
  111.   (primop fixnum-add ()
  112.     ((primop.generate self node)
  113.      (generate-fixnum-binop node 'add t nil))
  114.     ((primop.simplify self node)
  115.      (simplify-fixnum-add node))
  116.     ((primop.rep-wants self)
  117.      '(* *))
  118.     ((primop.type self node)
  119.      '#[type (proc #f (proc #f fixnum) fixnum fixnum)])))
  120.  
  121. (define-constant fixnum-logior
  122.   (primop fixnum-logior ()
  123.     ((primop.generate self node)
  124.      (generate-fixnum-binop node 'or t nil))
  125.     ((primop.simplify self node)
  126.      (simplify-fixnum-logior node))
  127.     ((primop.rep-wants self)
  128.      '(* *))
  129.     ((primop.arg-specs self)
  130.      '(scratch scratch))
  131.     ((primop.type self node)
  132.      '#[type (proc #f (proc #f fixnum) fixnum fixnum)])))
  133.  
  134. (define-constant fixnum-logxor
  135.   (primop fixnum-logxor ()
  136.     ((primop.generate self node)
  137.      (generate-fixnum-binop node 'xor t nil))
  138.     ((primop.simplify self node)
  139.      (simplify-fixnum-logxor node))
  140.     ((primop.rep-wants self)
  141.      '(* *))
  142.     ((primop.arg-specs self)
  143.      '(scratch scratch))
  144.     ((primop.type self node)
  145.      '#[type (proc #f (proc #f fixnum) fixnum fixnum)])))
  146.  
  147. (define-constant fixnum-logand
  148.   (primop fixnum-logand ()
  149.     ((primop.generate self node)
  150.      (generate-fixnum-binop node 'and t nil))
  151.     ((primop.simplify self node)
  152.      (simplify-fixnum-logand node))
  153.     ((primop.rep-wants self)
  154.      '(* *))
  155.     ((primop.arg-specs self)
  156.      '(scratch scratch))
  157.     ((primop.type self node)
  158.      '#[type (proc #f (proc #f fixnum) fixnum fixnum)])))
  159.  
  160. (define-constant (fixnum-lognot x)
  161.    (fixnum-logxor x -1))                                      
  162.  
  163. (define-constant (fixnum-negate x)
  164.   (fixnum-subtract 0 x))
  165.  
  166. (define-constant fixnum-subtract
  167.   (primop fixnum-subtract ()
  168.     ((primop.generate self node)
  169.      (generate-fixnum-binop node 'sub nil nil))
  170.     ((primop.rep-wants self)
  171.      '(* *))
  172.     ((primop.simplify self node)
  173.      (simplify-fixnum-subtract node))
  174.     ((primop.type self node)
  175.      '#[type (proc #f (proc #f fixnum) fixnum fixnum)])))
  176.  
  177. (define-constant (fixnum-ash integer amount)
  178.   (if (fixnum-less? amount 0) 
  179.       (fixnum-ashr integer (fixnum-subtract 0 amount))
  180.       (fixnum-ashl integer amount)))
  181.                                     
  182. (define-constant fixnum-ashl
  183.  (primop fixnum-ashl ()
  184.     ((primop.generate self node)
  185.      (generate-fixnum-binop node 'ashl nil t))
  186.     ((primop.simplify self node)
  187.      (simplify-fixnum-shift node fixnum-ashl))
  188.     ((primop.rep-wants self)
  189.      '(* rep/integer))
  190.     ((primop.arg-specs self)
  191.      '(scratch scratch))
  192.     ((primop.type self node)
  193.      '#[type (proc #f (proc #f fixnum) fixnum fixnum)])))
  194.                                     
  195. (define-constant fixnum-ashr
  196.  (primop fixnum-ashr ()
  197.     ((primop.generate self node)
  198.      (generate-fixnum-binop node 'ashr nil t))
  199.     ((primop.simplify self node)
  200.      (simplify-fixnum-shift node fixnum-ashr))
  201.     ((primop.rep-wants self)
  202.      '(* rep/integer))
  203.     ((primop.arg-specs self)
  204.      '(scratch scratch))
  205.     ((primop.type self node)
  206.      '#[type (proc #f (proc #f fixnum) fixnum fixnum)])))
  207.  
  208. (define-constant fixnum-add-with-overflow
  209.   (primop fixnum-add-with-overflow ()
  210.     ((primop.values-returned self) 1)                               
  211.     ((primop.generate self node)
  212.      (generate-op-with-overflow node 'add))
  213.     ((primop.presimplify self node)
  214.      (presimplify-to-funny-conditional node 1))
  215.     ((primop.conditional? self) t)
  216.     ((primop.make-closed self) primop/undefined-effect)
  217.     ((primop.conditional-type self node)
  218.      '#[type (proc #f (proc #f fixnum) (proc #f fixnum) top fixnum fixnum)])
  219.     ((primop.type self node)
  220.      '#[type (proc #f (proc #f boolean fixnum) fixnum fixnum)])))
  221.  
  222. (define-constant fixnum-multiply-with-overflow
  223.   (primop fixnum-multiply-with-overflow ()
  224.     ((primop.values-returned self) 1)                               
  225.     ((primop.generate self node)
  226.      (generate-op-with-overflow node 'multiply))
  227.     ((primop.presimplify self node)
  228.      (presimplify-to-funny-conditional node 1))
  229.     ((primop.conditional? self) t)
  230.     ((primop.make-closed self) primop/undefined-effect)
  231.     ((primop.conditional-type self node)
  232.      '#[type (proc #f (proc #f fixnum) (proc #f fixnum) top fixnum fixnum)])
  233.     ((primop.type self node)
  234.      '#[type (proc #f (proc #f boolean fixnum) fixnum fixnum)])))
  235.       
  236. (define-constant fixnum-subtract-with-overflow
  237.   (primop fixnum-subtract-with-overflow ()
  238.     ((primop.values-returned self) 1)                               
  239.     ((primop.generate self node)
  240.      (generate-op-with-overflow node 'subtract))
  241.     ((primop.presimplify self node)
  242.      (presimplify-to-funny-conditional node 1))
  243.     ((primop.conditional? self) t)
  244.     ((primop.make-closed self) primop/undefined-effect)
  245.     ((primop.conditional-type self node)
  246.      '#[type (proc #f (proc #f fixnum) (proc #f fixnum) top fixnum fixnum)])
  247.     ((primop.type self node)
  248.      '#[type (proc #f (proc #f boolean fixnum) fixnum fixnum)])))
  249.       
  250. (define-constant two-fixnums
  251.   (primop two-fixnums ()
  252.     ((primop.values-returned self) 2)                               
  253.     ((primop.generate self node)
  254.      (generate-two-fixnums node nil))
  255.     ((primop.presimplify self node)
  256.      (presimplify-to-funny-conditional node 2))
  257.     ((primop.conditional? self) t)
  258.     ((primop.make-closed self) primop/undefined-effect)
  259.     ((primop.conditional-type self node)
  260.      '#[type (proc #f (proc #f fixnum fixnum) (proc #f fixnum fixnum) 
  261.           top top top)])
  262.     ((primop.type self node)
  263.      '#[type (proc #f (proc #f boolean fixnum fixnum) top top)])))
  264.  
  265. (define-constant two-fixnums-for-compare?
  266.   (primop two-fixnums-for-compare? ()
  267.     ((primop.generate self node)
  268.      (generate-two-fixnums node t))
  269.     ((primop.presimplify self node)
  270.      (presimplify-to-conditional node))
  271.     ((primop.make-closed self) primop/undefined-effect)
  272.     ((primop.conditional? self) t)
  273.     ((primop.conditional-type self node)
  274.      '#[type (proc #f (proc #f) (proc #f) top top top)])
  275.     ((primop.type self node)
  276.      '#[type (proc #f (proc #f boolean) top top)])))
  277.  
  278.  
  279. (define-constant fixnum-multiply
  280.   (primop fixnum-multiply ()
  281.     ((primop.generate self node)
  282.      (generate-fixnum-multiply node))
  283.     ((primop.simplify self node)
  284.      (simplify-fixnum-multiply node))
  285.     ((primop.rep-wants self) '(rep/integer rep/integer))
  286.     ((primop.arg-specs self)
  287.      '(scratch scratch))
  288.     ((primop.type self node)
  289.      '#[type (proc #f (proc #f fixnum) fixnum fixnum)])))
  290.  
  291. (define-constant fixnum-divide
  292.   (primop fixnum-divide ()
  293.     ((primop.generate self node)
  294.      (generate-fixnum-divide node))
  295.     ((primop.simplify self node)
  296.      (simplify-fixnum-divide node))
  297.     ((primop.rep-wants self) '(rep/integer rep/integer))
  298.     ((primop.arg-specs self)
  299.      '(scratch scratch))
  300.     ((primop.type self node)
  301.      '#[type (proc #f (proc #f fixnum) fixnum fixnum)])))
  302.  
  303. (define-constant fixnum-remainder
  304.   (primop fixnum-remainder ()
  305.     ((primop.generate self node)
  306.      (generate-fixnum-remainder node))
  307.     ((primop.rep-wants self) '(rep/integer rep/integer))
  308.     ((primop.arg-specs self)
  309.      '(scratch scratch))
  310.     ((primop.type self node)
  311.      '#[type (proc #f (proc #f fixnum) fixnum fixnum)])))
  312.  
  313.  
  314.                                 
  315.  
  316.